👋 Welcome!
In this workshop, we will explore the advanced use of containers on HPC resources, like UCLA’s Hoffman2. This is a follow-up to a previous workshop “Containers for HPC Resources”
👀 Viewing the slides
https://github.com/ucla-oarc-hpc/WS_MakingContainers
WS_MakingContainers.pdf
Note
This presentation was created with Quarto and RStudio.
WS_MakingContainers.qmd
In this workshop, we will engage in hands-on exercises.
Requirements:
Alternative: Virtual Machine
Pre-configured Virtual Machine (VM) available on BOX
wscontainer.ova
Apptainer
Docker
Podman
Create 🛠️
Transfer ↪️
Run ▶️
1. Create 🛠️
Transfer
Run
.sif
$H2_CONTAINER_LOC
Create
Transfer
Run ▶️
Run Apptainer on your container:
Or run as a Batch (qsub) job
Create job script myjob.job
On Hoffman2, to use apptainer, all you need to do is load the module
module load intel/2022.1.1
There are serveral ways to build containers for Apptainer
Basic Build Command
apptainer build
to build new containersTypically, you will use the build command by
apptainer
commands from this new container.If you need a container that allows modifications, use the sandbox feature.
sudo
Note
This new Sandbox image does NOT have the .sif extension because this is a directory, not a single file.
--writable
flagOnce you’re satisfied with the changes, convert it to a SIF container:
This packages the modified sandbox into a read-only .sif container called myNewUbuntu.sif.
A definition file provides precise instructions on how to build and configure a container.
apptainer build myapp.sif myapp.def
This definition file details how the new container would be build
File: lolcow.def
%Bootstrap
- Specifies how to pull the base OS (e.g., from Docker).
%From
- Location and name of docker container
%labels
- Add textual metadata information to container%post
- Commands to setup the container from the baseOS the final container%environment
- Define environment variables inside container%runscript
- Specifies the command that runs when using apptainer run
In this example, we start with the Ubuntu 22.04 as a base OS. Then run commands from %post to create the final container.
This will execute the runscript section (which prints a date-stamped ASCII cow 🐄 message in rainbow colors 🌈).
Once you create a SIF file, this is the container that you can transfer to Hoffman2 to run or share with others.
Note
Can also build an SIF container from a Dockerfile
This example uses PyTorch 🧠
Similar to last week’s example
EX1
directory
pytorch.py
fileapptainer build
:
--sandbox
:
ubuntu_22.04_SB/
docker://ubuntu:22.04
This will create a Sandbox container ubuntu_22.04_SB
Next, we will start a WRITABLE interactive shell session in the sandbox image:
--writable
will allow us to modify the containerFrom here, we can run any commands we need to install PyTorch:
apt update
apt install -y python3 python3-pip
pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cpu
exit
Convert the sandbox container to a SIF file, pytorch.sif
In this example, we will create a container with a chemistry application that I created in Grad School. This code will calcuate the engery of a molecule.
To install, we need
We will build this container by:
quill.def
file has all steps needed to build the QUILL container.Bootstrap: docker
From: ubuntu:20.04
%labels
Author Charles Peterson <cpeterson@oarc.ucla.edu>
%post
apt-get update
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
git python3 python3-dev python3-pip \
libeigen3-dev ca-certificates cmake make gcc g++
rm -rf /var/lib/apt/lists/*
pip3 install pyscf
ln -s /usr/bin/python3 /usr/bin/python
mkdir -pv /apps
cd /apps
git clone https://github.com/charliecpeterson/QUILL
cd QUILL
mkdir build ; cd build
cmake ..
make
%environment
export PATH=/apps/QUILL/build:$PATH
QUILL.x test.inp
Dockerfile-quill
file is used by Docker to create containerFROM ubuntu:20.04
## Author Charles Peterson <cpeterson@arc.ucla.edu>
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
git python3 python3-dev python3-pip \
libeigen3-dev ca-certificates cmake make gcc g++ \
&& rm -rf /var/lib/apt/lists/*
RUN pip3 install pyscf ; ln -s /usr/bin/python3 /usr/bin/python
RUN mkdir -pv /apps \
&& cd /apps \
&& git clone https://github.com/charliecpeterson/QUILL \
&& cd QUILL \
&& mkdir build ; cd build \
&& cmake .. ; make
ENV PATH=/apps/QUILL/build:$PATH
In the previous slides, we created a SIF file (quill.sif), then transfer (scp) the container to Hoffman2.
Instead of this, we can upload our container to a Container Registry.
Lets create a repo on DockerHub
charliecpeterson
docker.io
ghcr.io
Push our final container to GitHub
DockerHub and GitHub Packages are popular cloud registries. You can create and deploy a local container registry.
Once the container is on Hoffman2, submit job.
#!/bin/bash
#$ -cwd
#$ -o quill.$JOB_ID
#$ -j y
#$ -l h_rt=1:00:00,h_data=15G
#$ -pe shared 1
#$ -l arch=intel-gold*
# load the job environment:
. /u/local/Modules/default/init/modules.sh
module load apptainer
# Container part: apptainer exec QUILL.sif
# Command: QUILL.x /apps/QUILL/input.inp
apptainer exec quill.sif QUILL.x test.inp
More information on using Definition files
More information on using Dockerfiles
MiniForge is a very popular python and R distributaion for simplifying package installation via the conda package manager
MiniForge can be tricky installing in a container due to environment setup.
This example will use MiniForge to install an application in a container.
We will go over creating a definition file for a example with MiniForge
We will install the software h2o.ai. This is a great machine learning platform that has Python and R libraries.
In this example, we will use MiniForge to install h2o packages inside python and R.
h2o.def
file
%runscript
to setup MiniForge env for apptainer run
$@
take arguments as a string from the command lineBootstrap: docker
From: ubuntu:22.04
%labels
Author Charles Peterson <cpeterson@oarc.ucla.edu>
%post
export DEBIAN_FRONTEND=noninteractive
apt -y update ; apt -y upgrade
apt install -y wget libbz2-dev wget git gcc libreadline-dev zlib1g-dev default-jre default-jdk
#Install Miniforge
cd /tmp
wget https://github.com/conda-forge/miniforge/releases/download/24.11.3-0/Miniforge3-24.11.3-0-Linux-x86_64.sh
bash Miniforge3-24.11.3-0-Linux-x86_64.sh -b -p /opt/miniforge
bash -c "source /opt/miniforge/etc/profile.d/conda.sh
conda create -n h2oai h2o -c h2oai -c conda-forge
"
%runscript
exec bash -c "source /opt/miniforge/etc/profile.d/conda.sh
conda activate h2oai
$@"
In the runscript, it will activate the conda environment, h2oai, and run the command that follows the apptainer run h2o.sif
command
Note
apptainer exec foo.sif [COMMAND]
apptainer run foo.sif
This example will show how to create a Jupyter container and start a Jupyter on Hoffman2
Size of container
Multi-Stage
approachQuestions? Comments? 🤔
Charles Peterson cpeterson@oarc.ucla.edu